<?php

namespace lvzmen\yii\cms\widgets\markdown;

use lvzmen\yii\cms\assets\markdown\GithubAsset;
use Yii;
use yii\base\Widget;
use yii\bootstrap\Html;

/**
 * A menu imitate the sidebar of https://docs.docker.com/get-started/
 *
 * @note It's depend on bootstrap;
 *
 * @example :
 * ```php

 * ```
 * @author chenzhiwei <chenzhiweiwk@qq.com>
 * @date   2021/08/31
 */
class Markdown extends Widget
{
    public $class = "";
    public $style = "";
    public $content = "# Hello World";

    public function init()
    {
        parent::init(); // TODO: Change the autogenerated stub

        GithubAsset::register($this->getView());
        $this->addCss();
        $this->addJs();
    }

    public function run()
    {
        return \yii\helpers\Markdown::process($this->content, "gfm");
    }


    public function addCss(){
        $css = <<<CSS
.cms-article {
    margin: 120px 250px;
}
.cms-article pre {
    padding: 0!important;
    border: 0 solid #ccc;
}
.cms-article blockquote {
    padding: 5px 20px 15px 20px!important;
    margin: 10px 0!important;
    font-size: 17.5px!important;
    border-left: 5px solid #eee!important;
    border-radius: 10px;
}
.cms-article blockquote:not(.important):not(.warning):not(.restricted) {
    background-color: rgba(159,209,249,0.2)!important;
    border-left-color: #076cad!important;
    font-size: unset!important;
}
.cms-article blockquote .title {
    font-weight: 600;
    font-size: 18px!important;
    color: #0d71bb;
}
.cms-article a img {
    margin: 0;
    padding: 0;
    border: 0;
    box-shadow: rgb(0 0 0) 0 0 0;
}
.cms-article img {
    margin-top: 10px;
    margin-bottom: 10px;
    max-width:100%;
    border: 1px solid #ccc;
    box-shadow: rgb(0 0 0) 0 0 8px;
}
CSS;
        $this->view->registerCss($css);
    }

    public function addJs(){
        $this->view->registerJs("hljs.highlightAll();", 4);
    }
}
